﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;

namespace MVC.Controllers
{
    public class ProxyController : Controller
    {
        // GET: Proxy
        public ActionResult Index()
        {
            return View();
        }

        // GET: Proxy
        public async Task<ActionResult> PowerSchool()
        {
            using (var client = new HttpClient())
            {
                var content = new FormUrlEncodedContent(new[] 
                    {
                        new KeyValuePair<string, string>("pstoken", "450670715xe9HSwp4VBKF72bVhoTqj84m9zfypHk1"),
                        new KeyValuePair<string, string>("username", "tchase"),
                        new KeyValuePair<string, string>("ldappassword", "Baba24L1nda13"),
                        new KeyValuePair<string, string>("password", "adb57fe4f5c0809a5efe68931627e1cb")
                    });
                //string baseUrl = "https://localhost:44302/Proxy/PowerSchoolTest";
                string baseUrl = "https://powerschool.rva.org/teachers/home.html";
                HttpResponseMessage response = await client.PostAsync(new Uri(baseUrl), content);
                string responseBody = await response.Content.ReadAsStringAsync();

                ViewBag.ResultMessage = responseBody;
            }

            return View();
        }

        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<ActionResult> PowerSchoolTest(string pstoken,string username,string ldappassword)
        //{
        //    ViewBag.ResultMessage = pstoken + username + ldappassword;
        //    return PartialView();
        //}
    }
}